package com.moyq5.mvc.maker.test.bean.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.custom.OwnerEntity;
import com.moyq5.mvc.maker.test.bean.enums.ChannelQrcodeAccountQrcodeMode;
import com.moyq5.mvc.maker.test.bean.enums.ChannelQrcodeAccountStatus;
import com.moyq5.mvc.maker.test.bean.enums.SysAccountType;
import com.moyq5.mvc.maker.test.bean.enums.SysPayType;

/**
 * 个人/企业收款码账户
 * @author Moyq5
 * @date 2018年9月13日
 */
@Entity
@Table(name = "tra_channel_qrcode_account")
@DynamicUpdate
public class TraChannelQrcodeAccount extends OwnerEntity implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 账户ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "account_id")
	private Long accountId;
	/**
	 * 支付渠道，用于区分是哪个支付渠道的收款码，微信、支付宝等
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "pay_type", nullable = false, columnDefinition="int(1) not null")
	private SysPayType payType;
    /**
	 * 账户类型，个人码、企业码等
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "account_type", nullable = false, columnDefinition="int(1) not null")
	private SysAccountType accountType; 
	/**
	 * 账户名，用于区分收款人，微信、支付宝等账户名。
	 */
	@Column(name = "account_name", nullable = false, length = 100)
	private String accountName;
	/**
	 * 备注名
	 */
	@Column(name = "remark_name", length = 100)
	private String remarkName;
	/**
	 * 在线时间，支付监听APP心跳时间
	 */
	@Column(name = "on_time", nullable = false, columnDefinition = "datetime default '1970-01-01 00:00:00'")
	private Date onTime;
	/**
	 * 状态，启用状态
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "status", nullable = false, columnDefinition="int(1) not null default '0'")
	private ChannelQrcodeAccountStatus status;
    /**
	 * 状态说明
	 */
	@Column(name = "status_descr", length = 100)
	private String statusDescr;
	/**
     * 收款码模式，多选
     * @see {@link ChannelQrcodeAccountQrcodeMode}
     */
    @Column(name = "qrcode_modes", nullable = false)
    private Integer qrcodeModes;
	/**
	 * 交易限制
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "confine_id")
	private TraConfine confine;
	/**
	 * 使用时间，最近一次被使用的时间点
	 */
	@Column(name = "use_time", nullable = false, columnDefinition = "datetime default '1970-01-01 00:00:00'")
	private Date useTime;
    /**
	 * 添加时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == status) {
			status = ChannelQrcodeAccountStatus.OFF;
		}
		if (null == statusDescr) {
			statusDescr = status.getText();
		}
		if (null == qrcodeModes) {
			qrcodeModes = 1<<ChannelQrcodeAccountQrcodeMode.ACCOUNT_TO_ACCOUNT.ordinal();
		}
		if (null == useTime) {
			useTime = new Date();
		}
		if (null == onTime) {
			onTime = new Date();
		}
		if (null == addTime) {
			addTime = new Date();
		}
	}

	public Long getAccountId() {
		return accountId;
	}

	public void setAccountId(Long accountId) {
		this.accountId = accountId;
	}

	public SysPayType getPayType() {
		return payType;
	}

	public void setPayType(SysPayType payType) {
		this.payType = payType;
	}

	public SysAccountType getAccountType() {
		return accountType;
	}

	public void setAccountType(SysAccountType accountType) {
		this.accountType = accountType;
	}

	public String getAccountName() {
		return accountName;
	}

	public void setAccountName(String accountName) {
		this.accountName = accountName;
	}

	public Date getOnTime() {
		return onTime;
	}

	public void setOnTime(Date onTime) {
		this.onTime = onTime;
	}

	public ChannelQrcodeAccountStatus getStatus() {
		return status;
	}

	public void setStatus(ChannelQrcodeAccountStatus status) {
		this.status = status;
	}

	public String getStatusDescr() {
		return statusDescr;
	}

	public void setStatusDescr(String statusDescr) {
		this.statusDescr = statusDescr;
	}

	public Date getAddTime() {
		return addTime;
	}

	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}

	public String getRemarkName() {
		return remarkName;
	}

	public void setRemarkName(String remarkName) {
		this.remarkName = remarkName;
	}

	public TraConfine getConfine() {
		return confine;
	}

	public void setConfine(TraConfine confine) {
		this.confine = confine;
	}

	public Date getUseTime() {
		return useTime;
	}

	public void setUseTime(Date useTime) {
		this.useTime = useTime;
	}

	public Integer getQrcodeModes() {
		return qrcodeModes;
	}

	public void setQrcodeModes(Integer qrcodeModes) {
		this.qrcodeModes = qrcodeModes;
	}

}
